﻿using System.Collections.Generic;
using System.Data;
using System.Linq;

namespace BLL
{
    public class LuongBLL
    {
        
        public List<Luong> GetAllLuong()
        {
           using( var  chamCongEn = new ChamCongEntities()){
                 return chamCongEn.Luongs.Include("CongNhan").ToList<Luong>();
            }
           
        }
        public Luong GetLuongById(int id)
        {
            ChamCongEntities chamCongEn = new ChamCongEntities();
            return chamCongEn.Luongs.Where(luong => luong.LuongId == id).FirstOrDefault();
        }
        public void InsertLuong(Luong luong)
        {
            ChamCongEntities chamCongEn = new ChamCongEntities();
            chamCongEn.Entry(luong).State = EntityState.Added;
            chamCongEn.SaveChanges();
        }
        public void UpdateLuong(Luong luong)
        {
            ChamCongEntities chamCongEn = new ChamCongEntities();
            chamCongEn.Entry(luong).State = EntityState.Modified;
            chamCongEn.SaveChanges();
        }
        public void DeleteLuong(Luong luong)
        {
            using (var cc = new ChamCongEntities())
            {
                cc.Entry(luong).State = EntityState.Deleted;
                cc.SaveChanges();
            };
            
        }
        public bool CheckThangNam(int thang=0,int nam=0)
        {
            ChamCongEntities chamCongEn = new ChamCongEntities();
            var luong = chamCongEn.Luongs.Where(t => t.Thang == thang && t.Nam == null).FirstOrDefault();
            if(luong!=null)
            {
                return false;
            }
            return true;
        }
    }
}
